#pragma once


#include "CSprite.h"

class Animation {
public:
	float m_Frame, m_speed;
	CSprite sprite;
	std::vector<RECT> m_frames;

    Animation() {}

    void set(CTexture& t, int x, int y, int w, int h, int count, float Speed) {
        m_Frame = 0;
        m_speed = Speed;

        for (int i = 0; i < count; i++) {
            RECT r;
            r.left = x + i * w;
            r.right = w + r.left;
            r.top = y;
            r.bottom = h + r.top;
            m_frames.push_back(r);
        }

        sprite.setTexture(t);
        sprite.setOrigin(w / 2, h / 2);
        sprite.setTextureRect(m_frames[0]);
    }


    void update() {
        m_Frame += m_speed;
        int n = m_frames.size();
        if (m_Frame >= n) m_Frame -= n;
        if (n > 0) sprite.setTextureRect(m_frames[int(m_Frame)]);
    }

    bool isEnd() {
        return m_Frame + m_speed >= m_frames.size();
    }
};

